
PY3		?= python3
PIP		?= pip3
PYTEST	?= pytest

ifeq ($(V),1)
Q		:=
endif
Q		?= @

TARGETS-build += build build_py build_ext build_clib build_scripts
PHONY += $(TARGETS-build)
$(TARGETS-build):
	$(Q)$(PY3) setup.py $@


TARGETS-install += install_lib install_headers install_scripts install_data
PHONY += $(TARGETS-install)
$(TARGETS-install):
	$(Q)$(PY3) setup.py $@

TARGETS-dist = sdist bdist bdist_dumb bdist_rpm bdist_wheel
PHONY += $(TARGETS-dist)
$(TARGETS-dist):
	$(Q)$(PY3) setup.py $@

PHONY += wheel
wheel:
	$(Q)$(PIP) wheel --no-deps --wheel-dir dist .

PHONY += clean distclean
clean:
	$(Q)$(PY3) setup.py clean

distclean: clean
	$(Q)rm -rf build dist
	$(Q)find ./ -name '*.pyc' -delete
	$(Q)find ./ -name '*.o' -delete
	$(Q)find ./ -name 'build' -type d | xargs --no-run-if-empty rm -r
	$(Q)find ./ -name 'dist' -type d | xargs --no-run-if-empty rm -r
	$(Q)find ./ -name '__pycache__' -type d | xargs --no-run-if-empty rm -r
	$(Q)find ./ -name '*.egg-info' -type d | xargs --no-run-if-empty rm -r


PHONY += install develop
install:
	$(Q)$(PIP) install -U .

develop:
	$(Q)$(PIP) install -e .

PHONY += uninstall
uninstall:
	$(Q)$(PIP) uninstall -y ctools

PHONY += check
check:
	$(Q)$(PY3) setup.py check


PHONY += test
test:
	$(Q)$(PYTEST)

PHONY += help help-commands
help help-commands:
	$(Q)$(PY3) setup.py --$@


.PHONY: $(PHONY)
